/**
 * 
 */
package qy.jalgotrade.broker.backtesting;

import qy.jalgotrade.broker.Order;

/**
 * A :class:`Commission` class that charges a percentage of the whole trade.
 * 
 * @author qy
 *
 */
public class TradePercentage extends Commission {

	/**
	 * The percentage to charge. 0.01 means 1%, and so on. It must be smaller than 1.
	 */
	private double __percentage;

	/**
	 * 
	 * @param percentage
	 *            The percentage to charge. 0.01 means 1%, and so on. It must be smaller than 1.
	 */
	public TradePercentage(double percentage) {

		assert percentage >= 0 && percentage < 1;
		__percentage = percentage;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see qy.jalgotrade.broker.backtesting.Commission#calculate(qy.jalgotrade.broker.Order,
	 * double, double)
	 */
	@Override
	public double calculate(Order order, double price, double quantity) {

		return price * quantity * __percentage;
	}
}
